﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RentAWorker.Business.Interfaces;
using RentAWorker.Business.DTO;
using RentAWorker.DataAccess.Interfaces;
using RentAWorker.DataAccess.Entities;

namespace RentAWorker.Business.Impl
{
    public class DummyImplementation : IManageRequestService, ICustomerService, IManageCustomerService, IRentRequestService, IReferenceDataService
    {
        private Random Rnd = new Random();

        #region IManageRequestService Members

        public RentalService[] GetRentalServicesForManager(string status)
        {
            throw new NotImplementedException();
        }

        public void ApproveRentalService(int rentalServiceId)
        {
            throw new NotImplementedException();
        }

        public void RejectRentalService(int rentalServiceId)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region ICustomerService Members

        public int RegisterNewCustomer(Guid membershipId, string companyName)
        {
            return Rnd.Next(1000000);
        }

        public int GetCustomerForUser(Guid membershipId)
        {
            return Rnd.Next(1000000);
        }

        public Customer GetCustomer(int id)
        {
            return new Customer()
            {
                CustomerID = id,
                MembershipID = Guid.NewGuid(),
                Name = "Customer " + id.ToString(),
            };
        }

        #endregion

        #region ICustomerManagementService Members

        public Customer[] GetCustomers(string nameSearchString)
        {
            throw new NotImplementedException();
        }

        public void UpdateCustomer(Customer customer)
        {
            throw new NotImplementedException();
        }

        public void DeleteCustomer(int customerId)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IRentRequestService Members

        public SearchResourceResponse SearchAvailableResources(SearchResourceRequest request)
        {
            SearchResourceResponse Response = new SearchResourceResponse();

            //
            //  Add 15 machines
            //
            Response.MachineResources = new Machine[15];
            for (int i = 0; i < Response.MachineResources.Length; i++)
            {
                Response.MachineResources[i] =
                    new Machine()
                    {
                        Location = new Location() { LocationID = (short)i, LocationName = "Location " + i.ToString() },
                        MachineType = new MachineType() { MachineTypeID = (short)i, MachineTypeName = "Type " + i.ToString() },
                        Name = "Machine No. " + i.ToString(),
                        ResourceID = i,
                        SerialNo = "No. " + i.ToString(),
                        Status = (i % 2 == 0) ? "damanged" : "okay"
                    };
            }

            //
            // Add 20 Workers
            // 
            Response.PersonResource = new Worker[20];
            for (int i = 0; i < Response.PersonResource.Length; i++)
            {
                Response.PersonResource[i] =
                    new Worker()
                    {
                        Location = new Location() { LocationID = (short)i, LocationName = "Location " + i.ToString() },
                        Name = "Super Worker " + i.ToString(),
                        ResourceID = i + Response.MachineResources.Length,
                        SSNo = "abc " + i.ToString()
                    };
            }

            return Response;
        }

        public RentalServiceResponse RequestRentalService(RentalServiceRequest request)
        {
            if (request.LocationId >= 5)
            {
                return new RentalServiceResponse()
                {
                    Information = "Everything is okay!",
                    Succeeded = true
                };
            }
            else
            {
                return new RentalServiceResponse()
                {
                    Information = "Resource not available!",
                    Succeeded = false
                };
            }
        }

        public RentalServiceResponse GetRentalServiceForCustomer(RentalServiceForCustomerRequest request)
        {
            return new RentalServiceResponse()
            {
                Services = new RentalService[1] 
                {
                    new RentalService() { Customer = GetCustomer(request.CustomerId), StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(15), RentalServiceID = 1, Resource = new Machine() { ResourceID = 1, Name = "Machine 1", SerialNo = "1111", Status = "Okay", MachineType = new MachineType() { MachineTypeName = "mt 1", MachineTypeID = 1} } }
                }
            };
        }

        public RentalServiceResponse GetRentalServicesForCustomer(RentalServicesForCustomerRequest request)
        {
            return new RentalServiceResponse()
            {
                Services = new RentalService[5] 
                {
                    new RentalService() { Customer = GetCustomer(request.CustomerId), StartDate = DateTime.Now.AddDays(5), EndDate = DateTime.Now.AddDays(15), RentalServiceID = 1, Resource = new Machine() { ResourceID = 1, Name = "Machine 1", SerialNo = "1111", Status = "Okay", MachineType = new MachineType() { MachineTypeName = "mt 1", MachineTypeID = 1} } },
                    new RentalService() { Customer = GetCustomer(request.CustomerId), StartDate = DateTime.Now.AddDays(6), EndDate = DateTime.Now.AddDays(16), RentalServiceID = 2, Resource = new Machine() { ResourceID = 2, Name = "Machine 2", SerialNo = "2222", Status = "Damaged", MachineType = new MachineType() { MachineTypeName = "mt 2", MachineTypeID = 2} } },
                    new RentalService() { Customer = GetCustomer(request.CustomerId), StartDate = DateTime.Now.AddDays(7), EndDate = DateTime.Now.AddDays(17), RentalServiceID = 3, Resource = new Machine() { ResourceID = 3, Name = "Machine 3", SerialNo = "3333", Status = "Okay", MachineType = new MachineType() { MachineTypeName = "mt 3", MachineTypeID = 3} } },
                    new RentalService() { Customer = GetCustomer(request.CustomerId), StartDate = DateTime.Now.AddDays(8), EndDate = DateTime.Now.AddDays(18), RentalServiceID = 4, Resource = new Worker() { SSNo = "Sso 1", ResourceID = 4, Name="First Worker", Location= new Location() { LocationID = 1, LocationName= "Location 1" } } },
                    new RentalService() { Customer = GetCustomer(request.CustomerId), StartDate = DateTime.Now.AddDays(9), EndDate = DateTime.Now.AddDays(19), RentalServiceID = 4, Resource = new Worker() { SSNo = "Sso 2", ResourceID = 5, Name="Second Worker", Location= new Location() { LocationID = 2, LocationName= "Location 2" } } }
                }
            };
        }

        public RentalServiceResponse ChangeRentalServiceForCustomer(RentalServiceChangeRequest request)
        {
            return new RentalServiceResponse()
            {
                Succeeded = true,
                Information = "Done",
                Services = new RentalService[1] { new RentalService() { RentalServiceID = request.RentalServiceId, Customer = GetCustomer(1), Resource = new Worker() { ResourceID = 1, SSNo = "sso 1", Name = "First Worker", Location = new Location() { LocationName = "Location 1", LocationID = 1 } } } }
            };
        }

        #endregion

        #region IReferenceDataService Members

        public Location[] GetLocations()
        {
            List<Location> Response = new List<Location>();

            for (short i = 0; i < 20; i++)
            {
                Response.Add(
                    new Location() { LocationID = i, LocationName = "Location " + i.ToString() });
            }

            return Response.ToArray();
        }

        public MachineType[] GetMachineTypes()
        {
            List<MachineType> Response = new List<MachineType>();

            for (short i = 0; i < 15; i++)
            {
                Response.Add(
                    new MachineType() { MachineTypeID = i, MachineTypeName = "Machine Type " + i.ToString() });
            }

            return Response.ToArray();
        }

        public RentalServiceState[] GetRentStates()
        {
            List<RentalServiceState> States = new List<RentalServiceState>()
            {
                new RentalServiceState() { RentalServiceStateID = 1, RentalServiceStateName = "Pending" },
                new RentalServiceState() { RentalServiceStateID = 2, RentalServiceStateName = "Accepted" },
                new RentalServiceState() { RentalServiceStateID = 3, RentalServiceStateName = "Declined" }
            };
            return States.ToArray();
        }

        public string[] GetMachineStates(string prefix, int maxStates)
        {
            List<string> States = new List<string>()
            {
                "Okay", "Damaged", "Slow", "Demolished", "Super", "Overture", "Demo", "Superb", "Overused"
            };
            return States.ToArray();
        }

        #endregion
    }
}
